<?php

defined('__EAPI_BASE') or define('__EAPI_BASE', dirname(__FILE__));

class EAPICharacter extends EAPIxml{
	
	protected $charXML;
	
	public function __Construct($apiCore,EAPIUser $uObj){
		try{

			parent::__Construct($apiCore);
			$this->charXML = new SimpleXMLElement($this->getXML('/char/CharacterSheet.xml.aspx',$uObj));
					
		}catch (EAPIException $e){
			print $e;
			die();
		}catch (Exception $e){
			print "<pre>[{$e->getCode()}]: {$e->getMessage()}\n</pre>";
			die();
		}
		
	}
	public function __Destruct(){}
	
	public function getCharData($type){
		switch($type){
			case "characterID":
				return $this->getCharacterID();
				break;
			case "name":
				return $this->getName();
				break;
			case "race":
				return $this->getRace();
				break;
			case "bloodLine":
				return $this->getBloodLine();
				break;
			case "gender":
				return $this->getGender();
				break;
			case "corporationName":
				return $this->getCorporationName();
				break;
			case "corporationID":
				return $this->getCorporationID();
				break;
			case "cloneName":
				return $this->getCloneName();
				break;
			case "cloneSkillPoints":
				return $this->getCloneSkillPoints();
				break;
			case "balance":
				return $this->getBalance()." ISK";
				break;
			case "attributeEnhancers":
				return $this->getAttributeEnhancers();
				break;
			case "attributes":
				return $this->getAttributes();
				break;
			default:
				return NULL;
				break;
		}
	}

	public function getCharacterID(){
		return $this->charXML->result->{'characterID'};
	}
	
	public function getName(){
		return $this->charXML->result->{'name'};
	}
	
	public function getRace(){
		return $this->charXML->result->{'race'};
	}
	
	public function getBloodLine(){
		return $this->charXML->result->{'bloodLine'};
	}
	
	public function getGender(){
		return $this->charXML->result->{'gender'};
	}
	
	public function getCorporationName(){
		return $this->charXML->result->{'corporationName'};
	}
	
	public function getCorporationID(){
		return $this->charXML->result->{'corporationID'};
	}
	
	public function getCloneName(){
		return $this->charXML->result->{'cloneName'};
	}
	
	public function getCloneSkillPoints(){
		return $this->charXML->result->{'clonwSkillPoints'};
	}
	
	public function getBalance(){
		return $this->charXML->result->{'balance'};
	}
	
	public function getAttributeEnhancers(){
		foreach($this->charXML->result->attributeEnhancers as $type){
			foreach($type as $augment){
				$attEnh[$type][$augment->{'augmentatorValue'}] = $augment->{'augmentatorName'};
			}
		}
		return $attEnh;
	}
	
	public function getAttributes(){
		foreach($this->charXML->result->attributes as $node){
			foreach($node as $attribute => $value){
				$attArr[$attribute] = (string)$value;
			}
		}
		return $attArr;
	}
};
?>